package com.zzb.valid.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * @author create by zhouzongbo on 2020/10/27.
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultEntity<T> {

    private int code;

    private String message;

    private T data;

    public ResultEntity(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public ResultEntity(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultEntity(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResultEntity<T> success(T data) {
        return new ResultEntity<>(1, "成功", data);
    }

    public static <T> ResultEntity<T> failure(String message) {
        return new ResultEntity<>(0, message, null);
    }
}
